package vip.liux.contracts.shared.kits;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import vip.liux.core.utils.JsonUtils;

@Component
public class ApplicationKit {

    public static ApplicationContext INSTANCE;
    public static ObjectMapper OBJECT_MAPPER;


    public ApplicationKit(ApplicationContext context, ObjectMapper objectMapper) {
        INSTANCE = context;
        JsonUtils.setObjectMapper(objectMapper);
    }

    public static <T> T getBean(Class<T> clazz) {
        return INSTANCE.getBean(clazz);
    }

    public static <T> T getBean(String name, Class<T> clazz) {
        return INSTANCE.getBean(name, clazz);
    }

    @SuppressWarnings("unchecked")
    public static <T> T getBean(String name) {
        return (T) INSTANCE.getBean(name);
    }
}
